/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lairensi
 * @Date: 2021-08-31 12:48:08
 * @LastEditors: lairensi
 * @LastEditTime: 2021-08-31 12:48:08
 */
/*
 * @Author: yuzc 
 * @Date: 2020-08-12 14:24:28 
 * @Last Modified by: yuzc
 * @Last Modified time: 2020-08-13 13:42:21
 * 
 * 
 * 提供一个loading
 * 
 * Loading _loading = new Loading();
 * _loading.showLoading(context,text);
 * _loading.closeLoading(context);
 * 
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Loading {
  bool isLoding = false; // 判断是否在loading状态
  // 显示Loading
  void showLoading(context, [String text]) {
    isLoding = true;
    text = text ?? "加载中...";
    showDialog(
        barrierDismissible: false,
        context: context,
        builder: (context) {
          return Center(
            child: Container(
              decoration: BoxDecoration(
                  // color: Colors.white,
                  // borderRadius: BorderRadius.circular(3.0),
                  // boxShadow: [
                  //   //阴影
                  //   BoxShadow(
                  //     color: Colors.black12,
                  //     //offset: Offset(2.0,2.0),
                  //     blurRadius: 10.0,
                  //   )
                  // ]
                  ),
              // padding: EdgeInsets.all(2),
              // margin: EdgeInsets.all(2),
              constraints: BoxConstraints(minHeight: 30.w, minWidth: 30.w),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  SizedBox(
                    height: 25.w, // 同宽高
                    width: 25.w, // 同宽高
                    child: CircularProgressIndicator(
                      strokeWidth: 1,
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 20.0),
                    child: Text(
                      text,
                      style: TextStyle(
                        inherit: false,
                        color: Colors.white,
                        fontSize: 14.sp,
                        // decoration: TextDecoration.underline,
                        // decorationStyle: TextDecorationStyle.dashed
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }

  // 关闭Loading
  void closeLoading(context) {
    isLoding = false;
    Navigator.of(context).pop();
  }
}
